using System.ComponentModel;
using System.Linq;
using System.ServiceModel.DomainServices.Client;
using YouFood.Web;
using YouFood.Web.Model;

namespace YouFood.ViewModel
{
    public class OrderSubViewModel : INotifyPropertyChanged
    {
        #region Property

        private Order _order;
        public Order OrderLocal
        {
            get { return _order; }
            set { _order = value;
            NotifyPropertyChanged("OrderLocal");
            }
        }

        private Food _food;
        public Food FoodLocal
        {
            get { return _food; }
            set { _food = value;
            NotifyPropertyChanged("FoodLocal");
            }
        }
        
        private FoodDomainContext _foodContext = new FoodDomainContext();
        private OrderCookerDomainContext _orderContext = new OrderCookerDomainContext();

        #endregion

        #region Constructor

        public OrderSubViewModel(Order order)
        {
            OrderLocal = order;
            var query = _foodContext.GetFoodByIdQuery(order.FoodId);
            var foodData = _foodContext.Load(query);
            foodData.Completed += new System.EventHandler(foodData_Completed);
        }

        #endregion

        #region Methode
        
        public void ChangeStatus(int OrderStatus)
        {
            //_orderContext.
        }

        #endregion

        #region Event

        void foodData_Completed(object sender, System.EventArgs e)
        {
            var senders = (LoadOperation<Food>)sender;
            
            FoodLocal = senders.Entities.First();
        }

        #endregion

        #region INotifyProperty

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        #endregion
    }
}